﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZOVNP.Model.Abstracts;

namespace ZOVNP.WinView
{
    public partial class ProductTypeEditControl : UserControl
    {
        private IProductType _productType;

        public ProductTypeEditControl(IProductType productType)
        {
            ProductType = productType;
            InitializeComponent();
        }

        public IProductType ProductType
        {
            get { return _productType; }
            set
            {
                _productType = value;

                tbxName.Text = _productType != null ? _productType.Name : string.Empty;
                tbxDescription.Text = _productType != null ? _productType.Description : string.Empty;
                tbxUnitName.Text = _productType != null ? _productType.UnitName : string.Empty;
                tbxProperty1Name.Text = _productType != null ? _productType.Property1Name : string.Empty;
                tbxProperty2Name.Text = _productType != null ? _productType.Property2Name : string.Empty;
                tbxProperty3Name.Text = _productType != null ? _productType.Property3Name : string.Empty;
            }
        }

        private void tbxName_TextChanged(object sender, EventArgs e)
        {
            if (_productType == null)
                throw new InvalidOperationException();

            _productType.Name = tbxName.Text;
        }

        private void tbxDescription_TextChanged(object sender, EventArgs e)
        {
            if (_productType == null)
                throw new InvalidOperationException();

            _productType.Description = tbxDescription.Text;
        }

        private void tbxUnitName_TextChanged(object sender, EventArgs e)
        {
            if (_productType == null)
                throw new InvalidOperationException();

            _productType.UnitName = tbxUnitName.Text;
        }

        private void tbxProperty1Name_TextChanged(object sender, EventArgs e)
        {
            if (_productType == null)
                throw new InvalidOperationException();

            _productType.Property1Name = tbxProperty1Name.Text;
        }

        private void tbxProperty2Name_TextChanged(object sender, EventArgs e)
        {
            if (_productType == null)
                throw new InvalidOperationException();

            _productType.Property2Name = tbxProperty2Name.Text;
        }

        private void tbxProperty3Name_TextChanged(object sender, EventArgs e)
        {
            if (_productType == null)
                throw new InvalidOperationException();

            _productType.Property3Name = tbxProperty3Name.Text;
        }
    }
}
